package com.neusoft.hifly.lock.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 读取redis配置信息，封装到当前实体中
 * <p>
 * redis自动缓存异常处理：继承CachingConfigurerSupport，重写errorHandler方法
 */
@Component
public class RedissonConfig { // extends CachingConfigurerSupport 

	/**
	 * 连接类型，支持standalone-单机节点，sentinel-哨兵，cluster-集群，masterslave-主从
	 */
	@Value("${redisson.lock.server.type:standalone}")
	private String type;

	/**
	 * redis主机地址，ip：port，有多个用半角逗号分隔
	 */
	@Value("${redisson.lock.server.address:null}")
	private String address;

	/**
	 * redis 连接密码
	 */
	@Value("${redisson.lock.server.password:null}")
	private String password;

	/**
	 * 选取那个数据库
	 */
	@Value("${redisson.lock.server.database:0}")
	private int database;

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public int getDatabase() {
		return database;
	}

	public void setDatabase(int database) {
		this.database = database;
	}

	//	@Bean
	//	@Override
	//	public CacheErrorHandler errorHandler() {
	//		CacheErrorHandler cacheErrorHandler = new CacheErrorHandler() {
	//			@Override
	//			public void handleCacheGetError(RuntimeException e, Cache cache, Object key) {
	//				System.out.println(key);
	//			}
	//
	//			@Override
	//			public void handleCachePutError(RuntimeException e, Cache cache, Object key, Object value) {
	//				System.out.println(value);
	//			}
	//
	//			@Override
	//			public void handleCacheEvictError(RuntimeException e, Cache cache, Object key) {
	//
	//			}
	//
	//			@Override
	//			public void handleCacheClearError(RuntimeException e, Cache cache) {
	//
	//			}
	//		};
	//		return cacheErrorHandler;
	//	}

}
